<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Team Bonus Summary</title>
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="/js/jquery.leanModal.min.js"></script>
<link type="text/css" href="/css/start/jquery-ui-1.8.21.custom.css" rel="Stylesheet" />	
<script language="javascript"> 
function toggle(source) {
	  checkboxes = document.getElementsByTagName('input');
	  for(var i in checkboxes)
	  	checkboxes[i].checked = source.checked;
	}
$(function() {
	$( ".date" ).datepicker({ dateFormat: "yy-mm-dd",firstDay: 1 });
});	
function toggle(str) {
	var ele = document.getElementById(str);

	if(ele.style.display == "") {
		ele.style.display = "none";
  	}
	else {
		ele.style.display = "";
	}
}
function tickAll(source){
	var currentId = $(source).attr('id');
	var id = currentId.split("_");
	if(id[1] == 'cash'){
		var checkBoxId = 'id_bonus_cash_'+id[2];
	}else if (id[1] == 'bank'){
		var checkBoxId = 'id_bonus_bank_'+id[2];
	}
	if(source.checked){
		$('.'+ checkBoxId).prop('checked',true);
	}else{
		$('.'+ checkBoxId).prop('checked',false);
	}

}


function check(source){
	var currentId = $(source).attr('id');
	var id = currentId.split("_");
	var checkId = 'saveChange_'+id[2];
	$("#" + checkId).prop("disabled",false);
}
</script>

</head>
<body style="font-family:Arial, Helvetica, sans-serif; line-height:20px;">
<form method = "post" action = "">
<?php 
$payrollCycle = unserialize(PAYROLL_CYCLE_SELECT);
$stf = new Model_Payroll_Staffbonus();
$stDetail = new Model_DbTable_Roster_Stafflogindetail();
$stInfo = new Model_DbTable_Roster_Staffinfo();
$btype = new Model_Payroll_Staffbonustype();
$newPayRollCycle = array_reverse($payrollCycle,true);
?>
<h2>All Bonus Summary</h2>
<?php echo "<img src='/im/yes20.jpg' />"."All Done";  echo "<img src='/im/btn_edit_error.png' />"."Did But Not Finish"; echo "<img src='/im/no20.jpg' />"."Have Not Start";?>
<br/>
<?php foreach($newPayRollCycle as $cK => $cVal){
if($cK >= 17){?>

		<?php $stfDetail = array();
			  $stfDetail = $stf->listReleasePaymentStaff($cVal[0],$cVal[1]);?>
<div <?php if(empty($stfDetail)){ ?> style = "display:none;" <?php }?>>			  
<br/>
<h3><a href = "javascript:toggle('dT<?=$cK?>');"><?php if($cK <27){echo 2014 ;}else{echo 2015;}?> Payroll Cycle <?php if($cK < 27){echo ($cK);}else{echo ($cK-26);}?> ( <?php echo $cVal[0];?> ~ <?php echo $cVal[1];?> )</a></h3>
</div>
<?php 		
			if(!empty($stfDetail)){
				$sortArray = array();
				foreach($stfDetail as $k => $v){
						$sortArray[] = $v['paid_date'];
				}
				array_multisort($sortArray,SORT_ASC,$stfDetail);
			$total = count($stfDetail);
			$countCal = 0;
			$countPM = 0;
			$countDis = 0;
			$countPay = 0;
			foreach($stfDetail as $kStaff => $vStaff){
				if($vStaff['calculate_status'] == 'yes'){
					$countCal ++;
				}
				if($vStaff['pay_method_status'] == 'yes'){
					$countPM ++;
				}
				if($vStaff['display_status'] == 'yes'){
					$countDis ++;
				}
				if($vStaff['payment_status'] == 'yes'){
					$countPay ++;
				}

				?>
<?php 		} ?>
		<table border="0" cellspacing="1" cellpadding="5">
			<tr>
				<th>Calculation Status</th>
				<th><?php if($countCal == $total){echo "<img src='/im/yes20.jpg' />";}elseif($countCal < $total && $countCal > 0){echo "<img src='/im/btn_edit_error.png' /> (".($total-$countCal).")";  }else{?><?php echo "<img src='/im/no20.jpg' />";  }?></th>
				<th>Confirm Payment</th>
				<th><?php if($countPM == $total){echo "<img src='/im/yes20.jpg' />";}elseif($countPM < $total && $countPM > 0){echo "<img src='/im/btn_edit_error.png' /> (".($total-$countPM).")";  }else{?><?php echo "<img src='/im/no20.jpg' />";  }?></th>
				<th>Display to Staff</th>
				<th><?php if($countDis == $total){echo "<img src='/im/yes20.jpg' />";}elseif($countDis < $total && $countDis > 0){echo "<img src='/im/btn_edit_error.png' /> (".($total-$countDis).")";  }else{?><?php echo "<img src='/im/no20.jpg' />";  }?></th>
				<th>Pay to Staff</th>
				<th><?php if($countPay == $total){echo "<img src='/im/yes20.jpg' />";}elseif($countPay < $total && $countPay > 0){echo "<img src='/im/btn_edit_error.png' /> (".($total-$countPay).")";  }else{?><?php echo "<img src='/im/no20.jpg' />";  }?></th>
			</tr>
		</table>	
		<div id = "dT<?=$cK?>" style="display:none;">
		<h3>Have not Pay staff list<br/><br/>
		Cash List</h3>
		Bonus Paid On<input name="paid_date[<?php echo $cK?>]" id="paid_date_<?php echo $cK?>" type="text" class = "date" onclick = "check(this)" />
		Input Your Password<input name = "password[<?php echo $cK?>]" type = "password"></input><input name = "backToHold[<?php echo $cK?>]" type = "submit" value = "Back to Hold" style= "margin-left: 530px" onclick = "if(confirm('Are you sure?Clicked bonus would back to hold status')){} else {return false;};"></input><br/>
		<input type = "submit" id = "saveChange_<?php echo $cK?>" name = "saveChange[<?php echo $cK?>]" value = "Submit" disabled class = "saveChange_<?php echo $cK?>" ></input>
		<input type = "checkbox" id = "tickAll_cash_<?php echo $cK ?>" style= "margin-left: 730px;"onclick = "tickAll(this)"></input>Tick All
		<br/>
		<table border="1" cellspacing="0" cellpadding="5" style="font-size:13px;">
			<tr>
    			<td style="width:65px;">ID Bonus</td>
   			    <td style="width:120px;">Staff</td>
    			<td style="width:150px;">Bonus Type</td>
    			<td style="width:100px;">Total Amt</td>
    			<td style="width:180px;">Period</td>
    			<td style="width:100px;">Finalized with Payroll Cycle</td>
    			<td style="width:60px;">Already Paid Date</td>
    			<td style="width:60px;">Authorized</td>
    			<td>Comment</td>
  			</tr>
		    <?php foreach ($stfDetail as $k2 => $v2){
		    	$btypeRow = $btype->getStaffbonustype($v2['type_bonus']);
		    	$sdRow = $stDetail->getDetail($v2['id_staff']);
		    	$nName = $sdRow['ni'];
		    	$fName = Model_EncryptHelper::getSslPassword($sdRow['n']);
		    		if($v2['cancel_status'] != 'yes' && $v2['calculate_status'] == 'yes' && $v2['pay_method_status'] == 'yes' && $v2['display_status'] == 'yes'){
		    		  if($v2['pay_type'] == 1){?>
		    		  	<?php foreach ($payrollCycle as $k3 => $v3){
		    		  			if($v2['confirm_paydate'] >= $v3[0] && $v2['confirm_paydate'] <= $v3[1]){
		    		  				$payRollKey = $k3;	
		    		  			}
		    		  	}?>
		    		  
		    			<tr>
							<td><?php echo $v2['id_bonus'];?></td>
							<td><?php echo ucwords($nName." <br />[ ".$fName." ]");?></td>
							<td><?php echo $btypeRow['type_bonus']?></td>
							<td>$ <?php echo $v2['amt_total_bonus']?></td>
							<td><?php echo $v2['period_bonus_begin']." to ".$v2['Period_bonus_end'];?></td>
							<td><?php if($payRollKey < 27){echo "<span style = \"background-color:#2FF20D\">".$payRollKey."</span>"." (".$payrollCycle[$payRollKey][0]." ~ ".$payrollCycle[$payRollKey][1].")";}else{echo "<span style = \"background-color:#2FF20D\">".($payRollKey-26)."</span>"." (".$payrollCycle[$payRollKey][0]." ~ ".$payrollCycle[$payRollKey][1].")";} ?></td>
    						<td><?php  if($v2['paid_date']==""){?>
    							<input type="checkbox" name="id_bonus[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]" value="<?php echo $v2['id_bonus']?>" class = "id_bonus_cash_<?php echo $cK?>"/>
    							<?php  }else{
										echo $v2['paid_date'];
								}?></td>
							<td><?php echo $v2['author_person']?></td>
    						<td width="20"><?php echo $v2['detail_bonus']?></td>
							</tr>
		    		<?php }?>
		    	<?php }?>
		<?php }?>    
		</table> 
		<h3>Bank List</h3>
		<input type = "checkbox" id = "tickAll_bank_<?php echo $cK ?>" style= "margin-left: 730px;"onclick = "tickAll(this)"></input>Tick All
		<table border="1" cellspacing="0" cellpadding="5" style="font-size:13px;">
   			 <tr>
    			<td style="width:65px;">ID Bonus</td>
    			<td style="width:120px;">Staff</td>
    			<td style="width:150px;">Bonus Type</td>
    			<td style="width:100px;">Total Amt</td>
    			<td style="width:100px;">Pay Bank</td>
    			<td style="width:100px;">Super</td>
    			<td style="width:180px;">Period</td>
    			<td style="width:100px;">Finalized with Payroll Cycle</td>
    			<td style="width:100px;">Already Paid Date</td>
    			<td style="width:60px;">Authorized</td>
    			<td>Comment</td>
  			</tr>
			<?php foreach($stfDetail as $k2 => $v2){
				$btypeRow = $btype->getStaffbonustype($v2['type_bonus']);
				$sdRow = $stDetail->getDetail($v2['id_staff']);
				$nName = $sdRow['ni'];
				$fName = Model_EncryptHelper::getSslPassword($sdRow['n']);
				$leave = $stInfo->getStaffinfo($v2['id_staff']);
					if($v2['cancel_status'] != 'yes'  && $v2['calculate_status'] == 'yes' && $v2['pay_method_status'] == 'yes' && $v2['display_status'] == 'yes'){
						if($v2['pay_type'] == 2){?>
						<?php foreach ($payrollCycle as $k3 => $v3){
		    		  			if($v2['confirm_paydate'] >= $v3[0] && $v2['confirm_paydate'] <= $v3[1]){
		    		  				$payRollKey = $k3;	
		    		  			}
		    		  	}?>
						<tr>
							<td><?php echo $v2['id_bonus'];?></td>
							<td><?php echo ucwords($nName." <br />[ ".$fName." ]");?></td>
							<td><?php echo $btypeRow['type_bonus']?></td>
							<td align="left">$ <?php echo $v2['amt_total_bonus']?></td>
    						<td align="left">$ <?php echo $v2['amt_bank_bonus']?></td>
    						<td align="left">$ <?php echo $v2['amt_bonus_super']?></td>
    						<td><?php echo $v2['period_bonus_begin']." to ".$v2['Period_bonus_end'];?></td>
    						<td><?php if($payRollKey < 27){echo "<span style = \"background-color:#2FF20D\">".$payRollKey."</span>"." (".$payrollCycle[$payRollKey][0]." ~ ".$payrollCycle[$payRollKey][1].")";}else{echo "<span style = \"background-color:#2FF20D\">".($payRollKey-26)."</span>"." (".$payrollCycle[$payRollKey][0]." ~ ".$payrollCycle[$payRollKey][1].")";} ?></td>
    						<td> <?php  if($v2['paid_date']==""){?>
    								<input type="checkbox" name="id_bonus[<?php echo $cK?>][<?php echo $v2['id_bonus']?>]"  value="<?php echo $v2['id_bonus']?>" class = "id_bonus_bank_<?php echo $cK?>"/>
    							<?php  }else{
											echo $v2['paid_date'];
								}?></td>
							<td><?php echo $v2['author_person']?></td>
    						<td><?php echo $v2['detail_bonus']?></td>
  						</tr>
		
					<?php }?>
				<?php }?>			
		<?php }?>	
			</table>
			</div>
		<?php }else{?>
				<div style = "display:none;">
				<table border="0" cellspacing="1" cellpadding="5">
					<tr>
						<th>Calculation Status</th>
						<th><?php echo "<img src='/im/no20.jpg' />"; ?></th>
						<th>Confirm Payment</th>
						<th><?php echo "<img src='/im/no20.jpg' />"; ?></th>
						<th>Display to Staff</th>
						<th><?php echo "<img src='/im/no20.jpg' />"; ?></th>
						<th>Pay to Staff</th>
						<th><?php echo "<img src='/im/no20.jpg' />"; ?></th>
					</tr>
				</table>
				</div>
		<?php }?>
	<?php }?>			
<?php }?> 
</form>
</body>
</html>
